/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package otros;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 *
 * @author FERRETERIA
 */
public class Configuracion {
 
    private final static Logger log = Logger.getLogger(Configuracion.class);
    
    Properties properties = null;
 
    /** Configuration file name */
    public final static String CONFIG_FILE_NAME = "config.properties";
 
    /** Data base server */
    public final static String DATABASE_SERVER = "dataBaseServer";
 
    /** Data base name */
    public final static String DATABASE_CATALOG = "dataBaseCatalog";
 
    /** Data base user */
    public final static String DATABASE_USER = "dataBaseUser";
 
    /** Data base password */
    public final static String DATABASE_PSWD = "dataBasePassword";
    
    public final static String IMP_TICKET = "impTicket";
    public final static String IMP_NORMAL = "impNormal";
    public final static String IMP_PDF = "impPdf";
    public final static String CAJON = "impCajon";
    public final static String CAJON_COD = "codCajon";
    
    public final static String LOGO_IMP = "logoImp";
    public final static String LOGO_IMPT = "logoImpT";
    public final static String FUENTE = "fuenteTicket";
    
    public final static String MAXIMIZADO = "maximizado";
 
    private Configuracion() {
        Util.setConfiguracionLog(Util.LOG4_FICH);
        //PropertyConfigurator.configure("log4j.properties");
        
        try {
            Properties p = Util.obtenerArchivoPropiedades("conf/"+CONFIG_FILE_NAME);
            if (p.isEmpty()) {
                properties = new Properties();
                InputStream in = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE_NAME);
                properties.load(in);
            }
            else
                properties = p;
        } catch (IOException ex) {
            log.fatal(ex);
        }
    }//Configuration
 
    /**
     * Implementando Singleton
     *
     * @return
     */
    public static Configuracion getInstance() {
        return ConfiguracionHolder.INSTANCE;
    }
 
    private static class ConfiguracionHolder {
 
        private static final Configuracion INSTANCE = new Configuracion();
    }
 
    /**
     * Retorna la propiedad de configuración solicitada
     *
     * @param key
     * @return
     */
    public String getProperty(String key) {
        return this.properties.getProperty(key);
    }//getProperty
    
}
